#ifndef FACEVIDEOPAINTEDITEM_H
#define FACEVIDEOPAINTEDITEM_H

#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QVideoFrame>
#include <QCamera>
#include <QTimer>
#include <QtQml/qqml.h>
#include "cameravideobuffer.h"
class FaceVideoPaintedItem : public QQuickPaintedItem
{
    Q_OBJECT
    Q_PROPERTY(bool running READ running WRITE setRunning)    
    Q_PROPERTY(QObject* videobuf READ videobuf WRITE setVideobuf)
public:
    explicit FaceVideoPaintedItem(QQuickItem *parent = 0);

    void setRunning(bool r){
        if(mRunning==r)
            return;

        mRunning=r;
        if(r)
            connect(mpVideoBuffer,SIGNAL(newFrame(QVideoFrame)),this,SLOT(UpdateFrame(QVideoFrame)));
        else
            disconnect(mpVideoBuffer,SIGNAL(newFrame(QVideoFrame)),this,SLOT(UpdateFrame(QVideoFrame)));

    }
    bool running() const{
        return mRunning;
    }

    void setVideobuf(QObject* v)
    {
        mpVideoBuffer=qobject_cast<CameraVideoBuffer*>(v);
    }
    QObject* videobuf() const
    {
        return mpVideoBuffer;
    }
protected:
    void paint(QPainter *painter);

protected slots:
    void UpdateFrame(QVideoFrame);

private:
    CameraVideoBuffer *mpVideoBuffer;

    bool              mRunning;

};

#endif // FaceVideoPaintedItem_H
